import 'package:flutter/material.dart';

class SizeFit {
  static double screenWidth = 0;
  static double screenHeight = 0;
  static double rpx = 0;
  static double px = 0;

  // 初始化rpx（设计图以宽度 750rpx 为基准）
  static void initialize(BuildContext context, {double standardWidth = 750}) {
    screenWidth = MediaQuery.of(context).size.width;
    screenHeight = MediaQuery.of(context).size.height;
    rpx = screenWidth / standardWidth;
    px = screenWidth / standardWidth * 2;
  }

  static double setRpx(double size) => rpx * size;

  static double setPx(double size) => px * size;
}

extension IntFit on int {
  double get rpx => SizeFit.setRpx(toDouble());
  double get px => SizeFit.setPx(toDouble());
}
